import socket

# 创建套接字
# SOCK_DGRAM表示socket传输层使用tcp协议
client = socket.socket(family=socket.AF_INET, type=socket.SOCK_DGRAM)

while True:
    msg = input(">>")
    if len(msg) == 0: continue
    client.sendto(msg.encode("utf-8"), ('localhost', 9001))  # 向服务器发送数据
    data, addr = client.recvfrom(1024)  # 接收服务器的返回信息
    print("服务器返回数据：", data.decode())

client.close()  # 关闭套接字


